﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Collections;

namespace IBNet.UtilsDataStructuresAndExtensions
{
   /// <summary>
   /// Returns a read-only wrapper for a FixedLengthCollection&lt;T>.
   /// </summary>
   /// <typeparam name="T">The type of elements in the collection.</typeparam>
   [DebuggerDisplay("FirstElement: {FixedLengthCollection[0].ToString()}")]
   public class ReadOnlyFixedLengthCollection<T> : IEnumerable<T>
   {
      private readonly FixedLengthCollection<T> _fixedLengthCollection;

      public ReadOnlyFixedLengthCollection(
         FixedLengthCollection<T> fixedLengthCollection)
      {
         if (fixedLengthCollection == null)
            throw new ArgumentNullException("fixedLengthCollection");

         this._fixedLengthCollection = fixedLengthCollection;
      }

      public T this[int index]
      {
         get
         {
            T item = _fixedLengthCollection[index];
            return item;
         }
      }

      public IEnumerator<T> GetEnumerator()
      {
         return _fixedLengthCollection.GetEnumerator();
      }

      IEnumerator IEnumerable.GetEnumerator()
      {
         return _fixedLengthCollection.GetEnumerator();
      }
   }
}
